package cn.iocoder.yudao.module.xkfz.controller.admin;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.module.xkfz.domain.entity.basic.DepartmentScore;
import cn.iocoder.yudao.module.xkfz.domain.entity.basic.IndicatorTree;
import cn.iocoder.yudao.module.xkfz.domain.entity.operationalPerformance.MetricDirectScore;
import cn.iocoder.yudao.module.xkfz.domain.po.operationalPerformance.MetricDirectScorePo;
import cn.iocoder.yudao.module.xkfz.mapper.basic.DeptBasicMapper;
import cn.iocoder.yudao.module.xkfz.service.operationalPerformance.MetricDirectScoreService;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

@RestController
@RequestMapping("/metricDirectScore")
@Validated
@Slf4j
public class MetricDirectScoreController{
    @Autowired
    MetricDirectScoreService metricDirectScoreService;
    @Autowired
    DeptBasicMapper deptBasicMapper;
    @GetMapping("/queryIndicatorList")
    @Operation(summary = "指标得分列表")
    public CommonResult<List<IndicatorTree>> indicatorList(@RequestParam Map<String,String> map) {
        List<IndicatorTree> metricDirectScoreDtoList = metricDirectScoreService.queryIndicatorScore(map);
        for (IndicatorTree indicatorTree : metricDirectScoreDtoList) {
            List<DepartmentScore> departmentScores = indicatorTree.getDepartmentScores();
        }
        return success(metricDirectScoreDtoList);
    }
    @GetMapping("/queryIndicatorScoreAll")
    @Operation(summary = "指标得分")
    public CommonResult<List<Map<String, Object>>> queryIndicatorScoreAll(@RequestParam Map<String,String> map) {
        List<Map<String, Object>> maps = metricDirectScoreService.queryIndicatorScoreAll(map);
        return success(maps);
    }

    @PostMapping("/insertFillInScoreDirectly")
    @Operation(summary = "直接填写分数")
    public CommonResult<Boolean> insertFillInScoreDirectly(@RequestBody List<MetricDirectScorePo> list) {
        return success(metricDirectScoreService.insertMetricDirectScore(list));
    }

    @PostMapping("/updateInScoreDirectly")
    @Operation(summary = "直接修改分数")
    public CommonResult<Boolean> updateMetricDirectScore( @RequestBody List<MetricDirectScorePo> list) {
        return success(metricDirectScoreService.updateMetricDirectScore(list));
    }

    @GetMapping("/queryIndicatorDeptScore")
    @Operation(summary = "查询指定指标的分数")
    public CommonResult<List<MetricDirectScore>> queryIndicatorDeptScore(String indicatorId,String year) {
        return success(metricDirectScoreService.queryIndicatorDeptScore(indicatorId,year));
    }

    @GetMapping("/querySubIndicatorByParent")
    @Operation(summary = "根据父节点查询所有的叶子指标")
    public CommonResult<List<IndicatorTree>> querySubIndicatorByParent(String pIndicatorId, String year, String ksName) {
        return success(metricDirectScoreService.querySubIndicatorByParent(pIndicatorId, year, ksName));
    }

}
